package basicSort.insertSort;

public class InsertSort {
    public static void insert(int[] arr){
        if(arr.length<2){
            return;
        }

        for (int i = 1;i<arr.length;i++){
            int flag = arr[i];
            int j = i-1;
            while (j>=0&&arr[j]>flag){
                arr[j+1] = arr[j];
                j--;
            }
            arr[j+1] = flag;
        }

    }

    public static void main(String[] args) {
        int count = 5000;

        int[] arr = new int[count];

        //为数组随机赋值
        for ( int i = 0 ; i < count ; i++){
            arr[i] =(int) (Math.random() * count);
        }
        insert(arr);
        for ( int i = 0 ; i < count ; i++){
            System.out.println(arr[i]+" ");
        }
    }
}
